package com.pos.dao.impl;

import com.pos.dao.RoleDAO;
import com.pos.dao.UsersDAO;
import com.pos.pojo.Role;
import com.pos.pojo.Users;
import org.springframework.orm.hibernate5.HibernateTemplate;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class RoleDAOImpl extends HibernateTemplate implements RoleDAO {
    UsersDAO usersDAO;
    @Override
    public Set<String> listRoleNames(String userID) {
        Set<String> result = new HashSet<>();
        List<Role> roles = listRoles(userID);
        for (Role role : roles) {
            result.add(role.getRoleName());
        }
        return result;
    }

    @Override
    public List<Role> listRoles(String userID) {
        List<Role> roles = new ArrayList<>();
        Users user = usersDAO.getUserById(userID);
        if(null==user)
            return roles;
        roles = listRoles(user);
        return roles;

    }

    @Override
    public List<Role> listRoles(Users users) {
        List<Role> roles = new ArrayList<>();
        Role role = users.getRole();
        roles.add(role);
        return roles;
    }

    @Override
    public List<Role> list() {
        return null;
    }

    @Override
    public void add(Role role) {

    }

    @Override
    public void delete(int role_id) {

    }

    @Override
    public Role get(int role_id) {
        return null;
    }

    @Override
    public void update(Role role) {

    }
}
